const isMandatory = (key) => {
  const value = process.env[key]
  if (!value) {
    throw new Error(`Missing env variable ${key}`)
  }
  return value
}

const isOptional = (key) => {
  const value = process.env[key]
  return value
}

module.exports = {
  APP_API_HOST: isMandatory('APP_API_HOST'),
  APP_API_PORT: isMandatory('APP_API_PORT'),
  APP_LAUNCH_HOST: isMandatory('APP_LAUNCH_HOST'),
  APP_HOST: isOptional('APP_HOST'),
  APP_PROVIDER_HOST: isOptional('APP_PROVIDER_HOST'),

  DB_USER: isMandatory('DB_USER'),
  DB_PASSWORD: isMandatory('DB_PASSWORD'),
  DB_NAME: isMandatory('DB_NAME'),
  DB_HOST: isMandatory('DB_HOST'),
  DB_PORT: isMandatory('DB_PORT'),

  REDIS_HOST: isOptional('REDIS_HOST'),
  REDIS_PORT: isOptional('REDIS_PORT'),

  MAILER_EMAIL: isMandatory('MAILER_EMAIL'),
  MAILER_PASSWORD: isMandatory('MAILER_PASSWORD'),

  AWS_ACCESS_KEY_ID: isMandatory('AWS_ACCESS_KEY_ID'),
  AWS_SECRET_KEY: isMandatory('AWS_SECRET_KEY'),
  AWS_S3_BUCKET: isMandatory('AWS_S3_BUCKET'),
  AWS_S3_URL: isMandatory('AWS_S3_URL'),

  JPUSH_APP_KEY: isMandatory('JPUSH_APP_KEY'),
  JPUSH_MASTER_SECRET: isMandatory('JPUSH_MASTER_SECRET'),

  ACCESS_TOKEN_EXPIRATION_USER: +isOptional('ACCESS_TOKEN_EXPIRATION_USER') || 1440,
  ACCESS_TOKEN_EXPIRATION_ADMIN: +isOptional('ACCESS_TOKEN_EXPIRATION_ADMIN') || 1440,
  ACCESS_TOKEN_EXPIRATION_MERCHANT: +isOptional('ACCESS_TOKEN_EXPIRATION_MERCHANT') || 1440,

  UTILITY_TOKEN_EXPIRATION_USER: +isOptional('UTILITY_TOKEN_EXPIRATION_USER') || 1440,
  UTILITY_TOKEN_EXPIRATION_ADMIN: +isOptional('UTILITY_TOKEN_EXPIRATION_ADMIN') || 1440,
  UTILITY_TOKEN_EXPIRATION_MERCHANT: +isOptional('UTILITY_TOKEN_EXPIRATION_MERCHANT') || 1440,

  PAGINATION_LIMIT_DEFAULT: +isOptional('PAGINATION_LIMIT_DEFAULT') || 25,
}

